package com.atech.ebayadmin.common.pager;

import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils;
import com.atech.ebayadmin.common.pager.Pager;;


public class PagerHelper {

    public static Pager getPager(HttpServletRequest request) {
        String dispatcher = request.getParameter("dispatcher");
        if (dispatcher == null || !dispatcher.equals("dispatcher")) {
            return new Pager();
        }
        else {
            Pager pager = new Pager();
            String currentPage = request.getParameter("currentPage");
            if (StringUtils.isBlank(currentPage)) {
                currentPage = "1";
            }
            try {
                int cp = Integer.parseInt(currentPage);
                if (0 >= cp) {
                    cp = 1;
                }
                pager.setCurrentPage(cp);
            }
            catch (NumberFormatException e) {
                pager.setCurrentPage(1);
            }
            return pager;
        }
    }
}
